package com.baidu.controller;

import com.baidu.pojo.TbSpecification;
import com.baidu.service.TbSpecificationService;
import com.baidu.utils.ResultResponse;
import com.baidu.vo.SpecificationVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 规格管理
 */
@CrossOrigin
@RestController
@RequestMapping("/specification")
public class TbSpecificationController {
    @Autowired
    TbSpecificationService tbSpecificationService;

    /**
     * 规格列表  分页  多条件查询
     * @param pageNum
     * @param pageSize
     * @param tbSpecification
     * @return
     */
    @PostMapping("/list/{pageNum}/{pageSize}")
    public ResultResponse findTbSpecificationList(@PathVariable("pageNum") Integer pageNum,
                                                  @PathVariable("pageSize") Integer pageSize,
                                                  @RequestBody TbSpecification tbSpecification){
        return tbSpecificationService.findTbSpecificationList(pageNum,pageSize,tbSpecification);
    }

    /**
     * 规格新增
     * @param specificationVo
     * @return
     */
    @PostMapping("/save")
    public ResultResponse saveTbSpecification(@RequestBody SpecificationVo specificationVo){
        tbSpecificationService.saveTbSpecification(specificationVo);
        return ResultResponse.SUCCESS("添加成功");
    }

    /**
     * 规格管理回显
     * @param id
     * @return
     */
    @PostMapping("/query/{id}")
    public ResultResponse queryTbSpecificationById(@PathVariable("id") Long id){
        TbSpecification tbSpecification=tbSpecificationService.queryTbSpecificationById(id);
        return ResultResponse.SUCCESS(tbSpecification);
    }

    /**
     * 规格管理修改
     * @param specificationVo
     * @return
     */
    @PostMapping("/set")
    public ResultResponse updateTbSpecification(@RequestBody SpecificationVo specificationVo){
        tbSpecificationService.updateTbSpecification(specificationVo);
        return ResultResponse.SUCCESS("修改成功");
    }

    /**
     * 规格管理批删
     * @param ids
     * @return
     */
    @PostMapping("/del")
    public ResultResponse delTbSpecificationById(@RequestBody List<TbSpecification> ids){
        return tbSpecificationService.del(ids);
    }

    //规格列表
    @GetMapping("/list")
    public ResultResponse findTbSpecificationList(){
        List<TbSpecification> tbSpecificationList=tbSpecificationService.findList();
        return ResultResponse.SUCCESS(tbSpecificationList);
    }

}
